const App = {
    data() {
        return {
            form: {
                Merchant_SerialNumber: '',
                Room_Type_SerialNumber: '',
                House_Room_SerialNumber:'',
                Check_In_Date: '',
                Check_Out_Date: '',
                ID_Card_Number:'',
                RoomNumber: 1,
                Guest_Name: '',
                Contact_Phone: '',
                Open_ID: 'oxS4B7tyTRYszs_PFjslwTGAV6yE',
            },
            nodeKey:'',
            Merchant_Category_SerialNumber:'',
            Blue_Plate_SerialNumber:'',
            room_type:[],
        }
    },
    beforeCreate() {
        function setRem() {
            const designWidth = 750; // 设计稿宽度（rpx）
            const maxWidth = 540; // 可选：限制最大宽度（如手机端常见值）
            const screenWidth = Math.min(window.innerWidth, maxWidth);
            const scale = screenWidth / designWidth;
            document.documentElement.style.fontSize = scale + 'px';
        }
        setRem();//1rem = 0.5px 对标小程序在 375px 宽的屏幕上，1rpx = 0.5px（因为 750rpx / 375px = 2）
        window.addEventListener('resize', setRem);
    },
    mounted() {
        let ls_URL = window.location.href;
        this.nodeKey = getQueryObject(ls_URL, "nodeKey");// 获取 nodeKey 参数
        this.form.Merchant_SerialNumber = getQueryObject(ls_URL, "Merchant_SerialNumber");
        this.form.Room_Type_SerialNumber = getQueryObject(ls_URL, "Room_Type_SerialNumber");
        this.form.House_Room_SerialNumber = getQueryObject(ls_URL, "House_Room_SerialNumber");
        this.getData( this.form.Room_Type_SerialNumber);
    },
    methods: {
        getData(Room_Type_SerialNumber) {
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                method: "post",
                data: {
                    Data: 'room_type',
                    Condition: `Room_Type_SerialNumber='${Room_Type_SerialNumber}'`,
                },
                success: (res) => {
                    this.room_type = res
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest)
                },
            });
        }, 
        handle() {
            let lJSONObject_DataSet = {
                Add: {
                    room_type_bookings: [this.form],
                }
            }
            console.log(lJSONObject_DataSet);
            // $.ajax({
            //     headers: requestHeaders("JSON"),
            //     url: `${mh}/generalBusiness/generalSaveByRequestBody`,
            //     method: "post",
            //     data: JSON.stringify({
            //         Data: lJSONObject_DataSet,
            //     }),
            //     success: (res) => {
            //         if (res.Status == 'success') {
            //             this.$message({
            //                 message: '成功',
            //                 type: 'success'
            //             });
            //         }
            //     },
            //     complete: (XMLHttpRequest) => {
            //         this.loading = false;
            //         requestPretreatment(XMLHttpRequest)
            //     }
            // });
        },
        handle1() {
            let lJSONObject_DataSet = {
                Add:{
                    room_type_check_ins:[this.form]
                }
            }
            $.ajax({
                headers: requestHeaders("JSON"),
                url: `${mh}/generalBusiness/generalSaveByRequestBody`,
                method: "post",
                data: JSON.stringify({
                    Data: lJSONObject_DataSet,
                }),
                success: (res) => {
                    if (res.Status == 'success') {
                        this.$message({
                            message: '入住成功',
                            type: 'success'
                        });
                    }
                },
                complete: (XMLHttpRequest) => {
                    this.loading = false;
                    requestPretreatment(XMLHttpRequest)
                }
            });
            // $.ajax({
            //     headers: requestHeaders(),
            //     url: `${mh}/generalBusiness/queryMultiTableByCondition`,
            //     type: "POST",
            //     data: {
            //         Data: JSON.stringify([{
            //             tableName: 'room_type_check_ins',
            //             Condition: window.btoa(unescape(encodeURIComponent("Room_Type_Bookings_SerialNumber='" + this.nodeKey + "'"))),
            //         }, {
            //             tableName: 'room_type_bookings',
            //             Condition: window.btoa(unescape(encodeURIComponent("Room_Type_Bookings_SerialNumber='" + this.nodeKey + "'"))),
            //         }]),
            //     },
            //     success: ({room_type_check_ins,room_type_bookings}) => {
            //         room_type_check_ins[0].Row_Status = '0';
            //         room_type_bookings[0].Row_Status = '5';
            //         console.log(room_type_bookings,room_type_check_ins);
            //         let lJSONObject_DataSet = {
            //             Modify:{
            //                 room_type_check_ins,
            //                 room_type_bookings
            //             }
            //         }
            //         $.ajax({
            //             headers: requestHeaders("JSON"),
            //             url: `${mh}/generalBusiness/generalSaveByRequestBody`,
            //             method: "post",
            //             data: JSON.stringify({
            //                 Data: lJSONObject_DataSet,
            //             }),
            //             success: (res) => {
            //                 if (res.Status == 'success') {
            //                     this.$message({
            //                         message: '成功',
            //                         type: 'success'
            //                     });
            //                 }
            //             },
            //             complete: (XMLHttpRequest) => {
            //                 this.loading = false;
            //                 requestPretreatment(XMLHttpRequest)
            //             }
            //         });
            //     },
            //     complete: (XMLHttpRequest) => {
            //         requestPretreatment(XMLHttpRequest);
            //     },
            //     dataType: "json",
            // })

        }
    },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
